package com.shuzixiangcun.controller.front;

import com.shuzixiangcun.entity.Rentaldetails;
import com.shuzixiangcun.service.front.RentaldetailsFServiceImpl;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 租借详情表(Rentaldetails)表控制层
 *
 * @author makejava
 * @since 2024-07-10 17:38:12
 */
@RestController
@RequestMapping("rentaldetails")
public class RentaldetailsFController {
    /**
     * 服务对象
     */
    @Resource
    private RentaldetailsFServiceImpl rentaldetailsService;



    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<Rentaldetails> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.rentaldetailsService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param rentaldetails 实体
     * @return 新增结果
     */
    @PostMapping("addRentaldetails")
    public ResponseEntity<Rentaldetails> add(Rentaldetails rentaldetails) {
        return ResponseEntity.ok(this.rentaldetailsService.insert(rentaldetails));
    }

    /**
     * 编辑数据
     *
     * @param rentaldetails 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<Rentaldetails> edit(Rentaldetails rentaldetails) {
        return ResponseEntity.ok(this.rentaldetailsService.update(rentaldetails));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.rentaldetailsService.deleteById(id));
    }

    @GetMapping("queryRentaldetails")
    public ResponseEntity<List<Rentaldetails>> queryRentaldetails() {
        return ResponseEntity.ok(this.rentaldetailsService.getRentaldetails());
    }

    @GetMapping("queryRentaldetailsAndUser")
    public ResponseEntity<Rentaldetails> queryRentaldetailsAndUser(Integer id) {
        return ResponseEntity.ok(this.rentaldetailsService.getRentaldetailsAndUser(id));
    }

}

